package org.leetcode.easy.leetcode83;


public class Solution
{
    public ListNode deleteDuplicates(ListNode head)
    {
        ListNode resultList = head;

        while (resultList!=null)
        {
            if (resultList.next==null)
            {
                return head;
            }

            if (resultList.val == resultList.next.val)
            {
                resultList.next=resultList.next.next;
            }else {
                resultList=resultList.next;
            }

        }

        return  head;
    }

    public static void main(String[] args) {
        ListNode testList = new ListNode(1, new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(3,null)))));

       //ListNode testList = new ListNode(1, new ListNode(1, new ListNode(1,null)));


        Solution solution = new Solution();
        solution.deleteDuplicates(testList);
    }
}
